package com.yeyks.appcontroller;

import com.yeyks.dal.domain.UserInfo;
import com.yeyks.dto.FishBallBillDTO;
import com.yeyks.model.Ajax.AjaxResponseBody;
import com.yeyks.service.FishBallBillService;
import com.yeyks.service.FishBallService;
import com.yeyks.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @author fuchangshuai
 * @date 2019/4/24 0024
 */
@Api(tags = "鱼丸接口", description = "鱼丸")
@Slf4j
@RestController
@RequestMapping(value = "/app/fish/ball")
public class FishBallController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private FishBallService fishBallService;
    @Autowired
    private FishBallBillService billService;

//    /**
//     * 获取用户鱼丸账户信息
//     *
//     * @param token
//     * @return
//     */
//    @ApiOperation(value = "获取用户鱼丸账户信息", notes = "获取用户鱼丸账户信息", response = FishBallDTO.class)
//    @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String")
//    @PostMapping(value = "/info")
//    public ResponseEntity<?> info(@RequestParam(name = "token") String token) {
//        UserInfo userInfo = userInfoService.tokenUserInfo(token);
//        FishBall fishBall = fishBallService.getFishBallNoCreate(userInfo.getId());
//        int remainAmount = fishBall.getTotalAmount() - fishBall.getUseAmount() < 0 ? 0 : fishBall.getTotalAmount() - fishBall.getUseAmount();
//        FishBallDTO fishBallDTO = new FishBallDTO(fishBall.getUserId(), fishBall.getTotalAmount(), remainAmount);
//        return ResponseEntity.ok(AjaxResponseBody.success(fishBallDTO));
//    }

    /**
     * 获取用户鱼丸明细
     *
     * @param token
     * @return
     */
    @ApiOperation(value = "获取用户鱼丸明细", notes = "获取用户鱼丸明细", response = FishBallBillDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "当前页", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "页码", defaultValue = "10", dataType = "int")
    })
    @PostMapping(value = "/bill")
    public ResponseEntity<?> bill(@RequestParam(name = "token") String token,
                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        UserInfo userInfo = userInfoService.tokenUserInfo(token);
        List<FishBallBillDTO> fishBallBillDTOS = billService.list(userInfo.getId(), pageNo, pageSize);
        return ResponseEntity.ok(AjaxResponseBody.success(fishBallBillDTOS));
    }
}
